package cn.iocoder.yudao.module.member.dal.mysql.order;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.admin.order.vo.AdminOrderPageVo;
import cn.iocoder.yudao.module.member.controller.app.order.vo.AppMemberCertificateOrderRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.order.vo.AppOrderPageVo;
import cn.iocoder.yudao.module.member.dal.dataobject.order.MemberCertificateOrderDo;
import cn.iocoder.yudao.module.member.dal.dataobject.order.MemberOrderDo;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface MemberOrderMapper extends BaseMapperX<MemberOrderDo> {

    default PageResult<MemberOrderDo> selectPage(Long loginUserId, AppOrderPageVo reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberOrderDo>()
                .eqIfPresent(MemberOrderDo::getUserId, loginUserId)
                .orderByDesc(MemberOrderDo::getId));
    }

    default PageResult<MemberOrderDo> selectPageAdmin( AdminOrderPageVo reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberOrderDo>()
                .eq(ObjectUtils.isNotNull(reqVO.getStatus()),MemberOrderDo::getStatus, reqVO.getStatus())
                .eq(ObjectUtils.isNotNull(reqVO.getUserId()),MemberOrderDo::getUserId, reqVO.getUserId())
                .in(CollectionUtil.isNotEmpty(reqVO.getIds()),MemberOrderDo::getUserId,reqVO.getIds())
                .orderByDesc(MemberOrderDo::getId));
    }
}
